package kr.pe.johnkim.sendme.activity;


import kr.pe.johnkim.sendme.provider.SendMeLog;
import kr.pe.johnkim.sendme.rest.SendMeLogRest;
import kr.pe.johnkim.sendme.util.SendMeActivityManager;
import kr.pe.johnkim.sendme.util.SendMeCommon;
import kr.pe.johnkim.sendme.util.SendMeConstant;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;

public class SendMeSubSettingsMessageAlarmActivity extends Activity {

	public static String TAG = SendMeSubSettingsMessageAlarmActivity.class.getSimpleName();
	
	
	// 액티비티 매니저를 가져 온다.
	private SendMeActivityManager sendMeActivityManager = SendMeActivityManager.getInstance();
	
	ImageButton imageButtonTopBack;
	ImageButton imageButtonTopMainMenu;
	
	ToggleButton toggleButtonMessageReceiveOnOff;
	ToggleButton toggleButtonMessagePopUpOnOff;
	
	// 알림 방법.
	ImageButton imageButtonSoundCheck;
	ImageButton imageButtonVibrationCheck;
	ImageButton imageButtonNoSoundCheck;
	       
	// 알림 소리. 
	ImageButton imageButtonSoundSelectDefault;
	ImageButton imageButtonSoundSelect1;
	ImageButton imageButtonSoundSelect2;
	
	
	
	Button confirmBtn;
	
	View messageSoundSettingLayout;
	TextView messageSettingTitleTxt;
	int messageSettingTitleTxtCount = 0;
	
	boolean  isToggleButtonMessageReceiveOn;
	boolean  isToggleButtonMessagePopUpOn;
	int checkedRadioGroupMessageAlarmMethod;
	int checkedRadioGroupMessageAlarmMethodSound;

	// 사용자 휴대 전화번호.
	private String PHONE_NUMBER = "";
	
	// 로그를 남긴다
	private static final int THREAD_REGISTER_LOG = 100;
	
	// 정보 저장에 성공했다는 toast 를 띄운다.
	private static final int THREAD_SUCCESS_SAVE_INFO = 109;
	
	// 정보 저장에 실패했다는 dialog 를 띄운다.
	private static final int THREAD_FAIL_SAVE_INFO = 111;
	
	// 화면에 설정값을 세팅한다.
	private static final int THREAD_SET_SCREEN_WITH_PREFERENCE_DATE = 112;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		// 커스텀 타이블 바를 설정 한다.
		Window window = getWindow();
		window.requestFeature(Window.FEATURE_CUSTOM_TITLE);
				
		setContentView(R.layout.activity_send_me_sub_settings_message_alarm);
		
		window.setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_bar_03);
		
		// 액티비티 매니저에 담는다.
		sendMeActivityManager.addActivity(this);
		
		// 뒤로 가기 화살표 버튼을 설정 한다.
				imageButtonTopBack = (ImageButton)findViewById(R.id.imageButtonTopBack);
				imageButtonTopBack.setOnClickListener(new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub

						Intent intent = new Intent(returnThis(), SendMeSettingsActivity.class);
						startActivity(intent);
						
						// 화면을 닫는다.
						sendMeActivityManager.removeActivity(SendMeSubSettingsMessageAlarmActivity.this);
						finish();
					}
				});

				// 타이틀바의 메인 메뉴 버튼을 설정 한다.
				imageButtonTopMainMenu = (ImageButton)findViewById(R.id.imageButtonTopMainMenu);
				imageButtonTopMainMenu.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						Log.i(TAG, "pressed top main menu.");

						// 메인 메뉴 화면을 출력 한다.
						Intent i = new Intent(SendMeSubSettingsMessageAlarmActivity.this, SendMeMainMenuActivity.class);
						startActivity(i);
						
						// 화면을 닫는다.
						sendMeActivityManager.removeActivity(SendMeSubSettingsMessageAlarmActivity.this);
						finish();
					}
				});
		
		// 메시지 알림 설정 on/off
		toggleButtonMessageReceiveOnOff = (ToggleButton) findViewById(R.id.toggleButtonMessageReceiveOnOff);
		toggleButtonMessageReceiveOnOff.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				// TODO Auto-generated method stub
				if(isChecked){
					Log.d(TAG,"toggleButtonMessageReceiveOnOff isChecked:"+isChecked);
				}else{
					Log.d(TAG,"toggleButtonMessageReceiveOnOff isChecked:"+isChecked);
				}
				isToggleButtonMessageReceiveOn = isChecked;
			}
		});
		
		// 팝업 설정 on/off
		toggleButtonMessagePopUpOnOff = (ToggleButton) findViewById(R.id.toggleButtonMessagePopUpOnOff);
		toggleButtonMessagePopUpOnOff.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				// TODO Auto-generated method stub
				if(isChecked){
					Log.d(TAG,"toggleButtonMessagePopUpOnOff isChecked:"+isChecked);
				}else{
					Log.d(TAG,"toggleButtonMessagePopUpOnOff isChecked:"+isChecked);
				}
				isToggleButtonMessagePopUpOn = isChecked;
			}
		});
		
		// 알림 방법 체크시 동작
		imageButtonSoundCheck = (ImageButton) findViewById(R.id.imageButtonSoundCheck);
		imageButtonSoundCheck.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				checkedRadioGroupMessageAlarmMethod = 1;
				// 세팅한다.
				mHandler.sendMessage(mHandler.obtainMessage(THREAD_SET_SCREEN_WITH_PREFERENCE_DATE));
			}
		});
		imageButtonVibrationCheck = (ImageButton) findViewById(R.id.imageButtonVibrationCheck);
		imageButtonVibrationCheck.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				checkedRadioGroupMessageAlarmMethod = 2;
				// 세팅한다.
				mHandler.sendMessage(mHandler.obtainMessage(THREAD_SET_SCREEN_WITH_PREFERENCE_DATE));
			}
		});
		imageButtonNoSoundCheck = (ImageButton) findViewById(R.id.imageButtonNoSoundCheck);
		imageButtonNoSoundCheck.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				checkedRadioGroupMessageAlarmMethod = 3;
				// 세팅한다.
				mHandler.sendMessage(mHandler.obtainMessage(THREAD_SET_SCREEN_WITH_PREFERENCE_DATE));
			}
		});
		
		imageButtonSoundSelectDefault = (ImageButton) findViewById(R.id.imageButtonSoundSelectDefault);
		imageButtonSoundSelectDefault.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				checkedRadioGroupMessageAlarmMethodSound = 1;
				// 세팅한다.
				mHandler.sendMessage(mHandler.obtainMessage(THREAD_SET_SCREEN_WITH_PREFERENCE_DATE));
			}
		});
		imageButtonSoundSelect1 = (ImageButton) findViewById(R.id.imageButtonSoundSelect1);
		imageButtonSoundSelect1.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				checkedRadioGroupMessageAlarmMethodSound = 2;
				// 세팅한다.
				mHandler.sendMessage(mHandler.obtainMessage(THREAD_SET_SCREEN_WITH_PREFERENCE_DATE));
			}
		});
		imageButtonSoundSelect2 = (ImageButton) findViewById(R.id.imageButtonSoundSelect2);
		imageButtonSoundSelect2.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				checkedRadioGroupMessageAlarmMethodSound = 3;
				// 세팅한다.
				mHandler.sendMessage(mHandler.obtainMessage(THREAD_SET_SCREEN_WITH_PREFERENCE_DATE));
			}
		});
		messageSoundSettingLayout = findViewById(R.id.messageSoundSettingLayout);
		messageSettingTitleTxt = (TextView) findViewById(R.id.messageSettingTitleTxt);
		messageSettingTitleTxt.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				messageSettingTitleTxtCount = messageSettingTitleTxtCount + 1;
				if(messageSettingTitleTxtCount > 15){
					messageSoundSettingLayout.setVisibility(View.VISIBLE);
				}
				if(messageSettingTitleTxtCount > 20){
					messageSoundSettingLayout.setVisibility(View.GONE);
					messageSettingTitleTxtCount = 0;
				}
			}
		});
		
		
		
		
		
		
		
//		// 라디오 그룹 - 알림 방법 -> 변환 
//		radioGroupMessageAlarmMethod = (RadioGroup) findViewById(R.id.radio_group_message_alarm_method);
//		radioGroupMessageAlarmMethod.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
//			@Override
//			public void onCheckedChanged(RadioGroup group, int checkedId) {
//				// TODO Auto-generated method stub
////				Log.d(TAG,"onCheckedChanged::"+checkedId);
//				switch(checkedId) {
//					case R.id.radio_btn_sound:
//						Log.d(TAG,"radio_btn_sound");
//						checkedRadioGroupMessageAlarmMethod = 1;
//						break;
//					case R.id.radio_btn_vibration:
//						Log.d(TAG,"radio_btn_vibration");
//						checkedRadioGroupMessageAlarmMethod = 2;
//						break;
//					case R.id.radio_btn_no_sound:
//						Log.d(TAG,"radio_btn_no_sound");
//						checkedRadioGroupMessageAlarmMethod = 3;
//						break;
//				}
//			}
//		});
		
		
//		// 라디오 그룹 - 알림 소리 -> 주석 
//		radioGroupMessageAlarmMethodSound = (RadioGroup) findViewById(R.id.radio_group_message_alarm_method_sound);
//		radioGroupMessageAlarmMethodSound.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
//			@Override
//			public void onCheckedChanged(RadioGroup group, int checkedId) {
//				// TODO Auto-generated method stub
//				//						Log.d(TAG,"onCheckedChanged::"+checkedId);
//				switch(checkedId) {
//				case R.id.radio_btn_sound_default:
//					Log.d(TAG,"radio_btn_sound_default");
//					checkedRadioGroupMessageAlarmMethodSound = 1;
//					break;
//				case R.id.radio_btn_sound_type_a:
//					Log.d(TAG,"radio_btn_sound_type_a");
//					checkedRadioGroupMessageAlarmMethodSound = 2;
//					break;
//				case R.id.radio_btn_sound_type_b:
//					Log.d(TAG,"radio_btn_sound_type_b");
//					checkedRadioGroupMessageAlarmMethodSound = 3;
//					break;
//
//				}
//			}
//		});

		
		// 확인 버튼
		confirmBtn = (Button)findViewById(R.id.confirm_btn);
		confirmBtn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				new backgroundThreadSaveMessageAlarm().execute();
			}
		});
		
		// 설정파일을 가져 온다.
		this.selectPreferenceMessageAlarmData();
		
		// 로깅.
		mHandler.sendMessage(mHandler.obtainMessage(THREAD_REGISTER_LOG));
		
		// 세팅한다.
		mHandler.sendMessage(mHandler.obtainMessage(THREAD_SET_SCREEN_WITH_PREFERENCE_DATE));
		
	}

//	public void setPreferenceDataToScreen(){
//		
//		// 메시지 수신 알림 설정
//		if(isToggleButtonMessageReceiveOn){
//			toggleButtonMessageReceiveOnOff.setChecked(true);
//		}else{
//			toggleButtonMessageReceiveOnOff.setChecked(false);
//		}
//		// 메시지 팝업 알림 설정
//		if(isToggleButtonMessagePopUpOn){
//			toggleButtonMessagePopUpOnOff.setChecked(true);
//		}else{
//			toggleButtonMessagePopUpOnOff.setChecked(false);
//		}
//		
//		// 알림 방법 설정
//		switch(checkedRadioGroupMessageAlarmMethod){
//		case 1:
//			radioGroupMessageAlarmMethod.check(R.id.radio_btn_sound);
//			break;
//		case 2:
//			radioGroupMessageAlarmMethod.check(R.id.radio_btn_vibration);
//			break;
//		case 3:
//			radioGroupMessageAlarmMethod.check(R.id.radio_btn_no_sound);
//			break;
//		}
//		
//		// 알림 소리 설정
//		switch(checkedRadioGroupMessageAlarmMethodSound){
//		case 1:
//			radioGroupMessageAlarmMethodSound.check(R.id.radio_btn_sound_default);
//			break;
//		case 2:
//			radioGroupMessageAlarmMethodSound.check(R.id.radio_btn_sound_type_a);
//			break;
//		case 3:
//			radioGroupMessageAlarmMethodSound.check(R.id.radio_btn_sound_type_b);
//			break;
//		}
//	}
	
	
	/**
	 * 목록을 세팅해서 출력 한다.
	 */
	private Runnable setPreferenceDataToScreenOnUiThread = new Runnable() {

		@Override
		public void run() {
			// 메시지 수신 알림 설정
			if(isToggleButtonMessageReceiveOn){
				toggleButtonMessageReceiveOnOff.setChecked(true);
			}else{
				toggleButtonMessageReceiveOnOff.setChecked(false);
			}
			// 메시지 팝업 알림 설정
			if(isToggleButtonMessagePopUpOn){
				toggleButtonMessagePopUpOnOff.setChecked(true);
			}else{
				toggleButtonMessagePopUpOnOff.setChecked(false);
			}
			
			// 알림 방법 설정
			switch(checkedRadioGroupMessageAlarmMethod){
			case 1:
				imageButtonSoundCheck.setBackgroundResource(R.drawable.beige_checkbox_on);
				imageButtonVibrationCheck.setBackgroundResource(R.drawable.beige_checkbox_off);
				imageButtonNoSoundCheck.setBackgroundResource(R.drawable.beige_checkbox_off);
				break;
			case 2:
				imageButtonSoundCheck.setBackgroundResource(R.drawable.beige_checkbox_off);
				imageButtonVibrationCheck.setBackgroundResource(R.drawable.beige_checkbox_on);
				imageButtonNoSoundCheck.setBackgroundResource(R.drawable.beige_checkbox_off);
				break;
			case 3:
				imageButtonSoundCheck.setBackgroundResource(R.drawable.beige_checkbox_off);
				imageButtonVibrationCheck.setBackgroundResource(R.drawable.beige_checkbox_off);
				imageButtonNoSoundCheck.setBackgroundResource(R.drawable.beige_checkbox_on);
				break;
			}
			
			// 알림 소리 설정
			switch(checkedRadioGroupMessageAlarmMethodSound){
			case 1:
				imageButtonSoundSelectDefault.setBackgroundResource(R.drawable.beige_checkbox_on);		
				imageButtonSoundSelect1.setBackgroundResource(R.drawable.beige_checkbox_off);
				imageButtonSoundSelect2.setBackgroundResource(R.drawable.beige_checkbox_off);
				break;
			case 2:
				imageButtonSoundSelectDefault.setBackgroundResource(R.drawable.beige_checkbox_off);
				imageButtonSoundSelect1.setBackgroundResource(R.drawable.beige_checkbox_on);
				imageButtonSoundSelect2.setBackgroundResource(R.drawable.beige_checkbox_off);
				break;
			case 3:
				imageButtonSoundSelectDefault.setBackgroundResource(R.drawable.beige_checkbox_off);
				imageButtonSoundSelect1.setBackgroundResource(R.drawable.beige_checkbox_off);
				imageButtonSoundSelect2.setBackgroundResource(R.drawable.beige_checkbox_on);
				break;
			}
		}
	};
	
	/**
	 * Handler 를 정의 한다.
	 * 모든 Thread 를 등록해 놓고 호출 한다.
	 */
	private Handler mHandler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			switch(msg.what) {
			
			// 로그를 남긴다
			case THREAD_REGISTER_LOG : 
				threadRegisterLog();
				break;
			// 정보 저장에 성공했다는 toast 를 띄운다.
			case THREAD_SUCCESS_SAVE_INFO : 
				showToastSuccessSaveInfo();
				break;
			// 정보 저장에 실패했다는 dialog 를 띄운다.
			case THREAD_FAIL_SAVE_INFO : 
				showToastFailSaveInfo();
				break;
				
			// 화면에 설정 값을 세팅한다.
			case THREAD_SET_SCREEN_WITH_PREFERENCE_DATE:
//				setPreferenceDataToScreen();
				runOnUiThread(setPreferenceDataToScreenOnUiThread);
				break;

			}
		}
	};

	/////////////////////////////////////////////////////////////////////////////////////////////////////////////
	/**
	 * backgroundThreadSaveMessageAlarm
	 * 비동기  .  설정에 이름 저장
	 * @author blue
	 *
	 */
	public class backgroundThreadSaveMessageAlarm extends AsyncTask<Void, Void, Void>{
		private ProgressDialog dialog;
		@Override protected void onPostExecute(Void result) {  
			dialog.dismiss();
		} 
		@Override protected void onPreExecute() {  
			dialog = ProgressDialog.show(SendMeSubSettingsMessageAlarmActivity.this, "", "Save..", true);
		} 
		@Override protected Void doInBackground(Void... params) {  
			Log.d(TAG,"backgroundThreadSaveMessageAlarm");
			savePreferenceMessageAlarmData();
			return null; 
		}
	}
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// 서버 통신
	
//	/**
//	 * 인증번호를 요청 한다.
//	 */
//	public void threadRequestCertification() {
//		// 프로그레스 바를 출력 한다.
//		mHandler.sendMessage(mHandler.obtainMessage(THREAD_PROGRESS_BAR_VISIBLE));
//		
//		Thread thread = new Thread(new Runnable() {
//
//			public void run() {
//				// TODO Auto-generated method stub
//				SendMeCommon sendMeCommon = new SendMeCommon();
//				
//				SendMeCertification sendMeCertification = new SendMeCertification();
//				sendMeCertification.setPhoneNumber(editTextPhoneNumber.getText().toString());
//				sendMeCertification.setActivateYn("Y");
//				sendMeCertification.setModifyDate(sendMeCommon.getCurrentDate());
//				sendMeCertification.setRegisterDate(sendMeCommon.getCurrentDate());
//				
//				// 요청 후 사용자 휴대전화버호를 임시로 저장한다.
//				tempPhoneNumber = editTextPhoneNumber.getText().toString();
//				
//				SendMeCertificationRest sendMeRest = new SendMeCertificationRest();
//				SendMeCertification result = new SendMeCertification();
//				result = sendMeRest.requestCertification(sendMeCertification);
//				Log.i(TAG, "result : " + result.getResult());
//				
//				// 프로그레스 바를 감춘다.
//				mHandler.sendMessage(mHandler.obtainMessage(THREAD_PROGRESS_BAR_INVISIBLE));
//				
//				// 인증번호 요청에 성공하면 toast 를 띄워서 알려준다.
//				if(("SUCCESS").equals(result.getResult())) {
//					certificationNumber = result.getCertificationNumber();
//					
//					mHandler.sendMessage(mHandler.obtainMessage(THREAD_SMS_SEND_CERTIFICATION));
//					mHandler.sendMessage(mHandler.obtainMessage(THREAD_SET_CERTIFICATION_NUMBER));
//				}
//			}
//			
//		});
//		
//		thread.start();
//	}
	
	
	/**
	 * 로그를 남긴다	 
	 */
	public void threadRegisterLog() {
		Thread thread = new Thread(new Runnable() {
			public void run() {
				
				SendMeCommon sendMeCommon = new SendMeCommon();
				String nowTime = sendMeCommon.getCurrentDate();
				
				SendMeLog sendMeLog = new SendMeLog();
				sendMeLog.setPhoneNumber(PHONE_NUMBER);
				sendMeLog.setViewName(TAG);
				sendMeLog.setRegisterDate(nowTime);
				
				SendMeLogRest sendMeLogRest = new SendMeLogRest();
				
				sendMeLogRest.registerLog(sendMeLog);
			}
		});
		thread.start();
	}
	
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// 사용자 알림
	
	/**
	 * 정보 저장에 성공했다는 toast 를 띄운다.
	 */
	public void showToastSuccessSaveInfo() {
		CharSequence text = "변경사항이 저장되었습니다.";
		Toast toast = Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT);
		toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);
		toast.show();
	}
	/**
	 * 정보 저장에 실패했다는 toast 를 띄운다.
	 */
	public void showToastFailSaveInfo() {
		CharSequence text = "저장이 실패했습니다.";
		Toast toast = Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT);
		toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);
		toast.show();
	}
	
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 닫기 관련
	
	public Context returnThis(){
		return this;
	}
	
	
	/*
	 * 종료한다
	 */
	public void finishActivity(){
		sendMeActivityManager.removeActivity(SendMeSubSettingsMessageAlarmActivity.this);
		finish();
	}
//	/**
//	 * 뒤로 가기 버튼을 정의 한다.
//	 * 설치단계이기 때문에 뒤로가기 버튼을 터치하면 앱을 종료 한다.
//	 */
	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub
		Intent intent = new Intent(returnThis(), SendMeSettingsActivity.class);
		startActivity(intent);
		
		// 화면을 닫는다.
		sendMeActivityManager.removeActivity(SendMeSubSettingsMessageAlarmActivity.this);
		finish();
	}
//	
//	/**
//	 * 뒤로가기 버튼을 터치하면 alert 창을 띄우고 앱을 종료한다.
//	 */
//	private void showDialogSystemExit() {
//		new AlertDialog.Builder(SendMeSubSettingsMessageAlramActivity.this)
//		.setTitle("프로그램 종료")
//		.setMessage("SendMe 를 종료하시겠습니까?")
//		.setNegativeButton("취소", new DialogInterface.OnClickListener() {
//
//			@Override
//			public void onClick(DialogInterface dialog, int which) {
//
//			}
//		})
//		.setPositiveButton("확인", new DialogInterface.OnClickListener() {
//			
//			@Override
//			public void onClick(DialogInterface dialog, int which) {
//				// TODO Auto-generated method stub
//				sendMeActivityManager.finishAllActivity();
//			}
//		}).show();
//	}
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// preference 
	/**
	 * SharedPreference 정보를 확인 한다.
	 */
	public void selectPreferenceMessageAlarmData() {
		SharedPreferences mSharedPreference = getSharedPreferences(SendMeConstant.SENDME_PREFERENCE, Activity.MODE_PRIVATE);
		
		PHONE_NUMBER = mSharedPreference.getString("phone_number", "");
		isToggleButtonMessageReceiveOn = mSharedPreference.getBoolean("setting_message_receive_on", true);
		isToggleButtonMessagePopUpOn  = mSharedPreference.getBoolean("setting_message_popup_on", true);
		checkedRadioGroupMessageAlarmMethod  = mSharedPreference.getInt("setting_message_alarm_method", 2);
		checkedRadioGroupMessageAlarmMethodSound  = mSharedPreference.getInt("setting_message_alarm_method_sound", 1);
	}
	/**
	 * 설정파일에 저장한다
	 */
	public void savePreferenceMessageAlarmData() {
		try{
			SharedPreferences sharedPreferences = getSharedPreferences(SendMeConstant.SENDME_PREFERENCE, Activity.MODE_PRIVATE);
			SharedPreferences.Editor editor = sharedPreferences.edit();
			editor.putBoolean("setting_message_receive_on", isToggleButtonMessageReceiveOn);
			editor.putBoolean("setting_message_popup_on", isToggleButtonMessagePopUpOn);
			editor.putInt("setting_message_alarm_method", checkedRadioGroupMessageAlarmMethod);
			editor.putInt("setting_message_alarm_method_sound", checkedRadioGroupMessageAlarmMethodSound);
			editor.commit();
			mHandler.sendMessage(mHandler.obtainMessage(THREAD_SUCCESS_SAVE_INFO));
			
			Intent intent = new Intent(returnThis(), SendMeSettingsActivity.class);
			startActivity(intent);
			
			finishActivity();
		}catch(Exception e){
			mHandler.sendMessage(mHandler.obtainMessage(THREAD_FAIL_SAVE_INFO));
		}
	}

}
